using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Configuration.Design;
using Microsoft.Practices.EnterpriseLibrary.PolicyInjection.Configuration.Design;

namespace EntLibContrib.PolicyInjection.Design
{
    public class PolicyInjectionDesignManager : ConfigurationDesignManager
    {
        public override void Register(IServiceProvider serviceProvider)
        {
            new PolicyInjectionNodeMapRegistrar(serviceProvider).Register();
            new PolicyInjectionCommandRegistrar(serviceProvider).Register();
        }

        protected override void OpenCore(IServiceProvider serviceProvider, ConfigurationApplicationNode rootNode, System.Configuration.ConfigurationSection section)
        {
            foreach (MatchingRuleCollectionNode ruleCollecion in rootNode.Hierarchy.FindNodesByType(rootNode, typeof(MatchingRuleCollectionNode)))
            {
                new PolicyInjectionNodeBuilder(serviceProvider).BuildAdditionalMatchingRuleNodes(ruleCollecion);
            }
            base.OpenCore(serviceProvider, rootNode, section);
        }
    }
}
